"""处理图像用CNN，处理文本用Embedding"""
import torch
import torch.nn as nn

# nn.Embedding(num_embeddings-词典长度，embedding_dim-向量维度)
embed = nn.Embedding(10, 3)  # 10个词这里代表0 ~ 9这10个数字
print('embed.weight:')
print(embed.weight)
print('---------------------------')
"""[1,2,4,5]指分别取embed.weight中下标为1、2、4、5行的向量来组成新的张量"""
input1 = torch.LongTensor([[1,2,4,5],[4,3,2,9]])
out1 = embed(input1)
print(out1)
print('---------------------------')
embed2 = nn.Embedding(10, 3, padding_idx=0)
print('embed2.weight:')
print(embed2.weight)
print('---------------------------')
input2 = torch.LongTensor([[0,2,0,5]])
out2 = embed2(input2)
print(out2)

